local zhihe = fk.CreateSkill {
  name = "lingling__zhihe",
}

Fk:loadTranslationTable{
  ["lingling__zhihe"] = "治河",
  [":lingling__zhihe"] = "游戏开始时，你额外获得【水淹七军】、【韬光养晦】、【无中生有】各两张，这些牌不计入手牌上限且不能使用，"..
  "进入弃牌堆时移出游戏。当你受到伤害后，你令其中牌名不同的两张牌变为可以使用。",

  ["@@lingling__zhihe"] = "治河",
  ["#lingling__zhihe-invoke"] = "治河：令两张牌名不同的“治河”牌变为可以使用",
}

zhihe:addEffect(fk.GameStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zhihe.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {
      room:printCard("ling__drowning", Card.Spade, 3),
      room:printCard("ling__drowning", Card.Spade, 4),
      room:printCard("ling__hide_capacities", Card.Heart, 1),
      room:printCard("ling__hide_capacities", Card.Heart, 1),
      room:printCard("ling__ex_nihilo", Card.Heart, 7),
      room:printCard("ling__ex_nihilo", Card.Heart, 8),
    }
    for _, card in ipairs(cards) do
      room:setCardMark(card, zhihe.name, 1)
      room:setCardMark(card, "@@lingling__zhihe", 1)
      room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
    end
    room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, zhihe.name, nil, true, player)
  end,
})

zhihe:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(zhihe.name) and
      table.find(player:getCardIds("h"), function (id)
        return Fk:getCardById(id):getMark(zhihe.name) > 0 and
          table.find(player:getCardIds("h"), function (id2)
            return id ~= id2 and Fk:getCardById(id2):getMark(zhihe.name) > 0 and
              Fk:getCardById(id).name ~= Fk:getCardById(id2).name
          end) ~= nil
      end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local success, dat = room:askToUseActiveSkill(player, {
      skill_name = "lingling__zhihe_active",
      prompt = "#lingling__zhihe-invoke",
      cancelable = false,
    })
    if not (success and dat) then
      dat = {}
      dat.cards = {}
      for _, id in ipairs(player:getCardIds("h")) do
        if Fk:getCardById(id):getMark(zhihe.name) > 0 then
          if #dat.cards == 0 then
            table.insert(dat.cards, id)
          elseif Fk:getCardById(id).name ~= Fk:getCardById(dat.cards[1]).name then
            table.insert(dat.cards, id)
            break
          end
        end
      end
    end
    for _, id in ipairs(dat.cards) do
      room:setCardMark(Fk:getCardById(id), zhihe.name, 0)
    end
  end,
})

zhihe:addEffect("maxcards", {
  exclude_from = function (self, player, card)
    return card:getMark("@@lingling__zhihe") > 0
  end,
})

zhihe:addEffect("prohibit", {
  prohibit_use = function (self, player, card)
    return card and card:getMark(zhihe.name) > 0
  end,
})

return zhihe
